<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<div id="rightinfo" class="rightinfo"></div>

<!-- 模板 -->
<script id="list" type="text/html">
    <table class="tablelist">
        <thead>
        <tr>
        <th style="width:8%">编号</th>
        <th style="width:8%">重要等级</th>
        <th>操作记录</th>
        <th style="width:10%">操作员</th>
        <th style="width:15%">IP地址</th>
        <th style="width:18%">操作时间</th>
        </tr>
        </thead>
        <tbody>
        <%for(i = 0; i < list.length; i ++) {%>
            <tr <%=#(i%2 ==0) ?'':'class="odd"'%> data-id="<%=list[i].id%>">
            <td><%=list[i].id%></td>
            <td><%=#showLevel(list[i].level)%></td>
            <td><%=list[i].content%></td>
            <td><%=list[i].username%></td>
            <td><%=list[i].ip%></td>
            <td><%=dateFormat(list[i].add_time,'yyyy-MM-dd hh:mm:ss')%></td>
            </tr>
        <%}%>        
        </tbody>
    </table>   
    <div class="pagin">
        <div class="message">共<i class="blue"><%=record_count%></i>条记录，当前显示第&nbsp;<i class="blue"><%=page_num%>/<%=page_count%></i>&nbsp;页</div>
        <div class="paginList" id="page_bar"></div>
    </div>
    <div class="clearfloat"></div>
</script>

<!-- 脚本 -->
<script src="js/template-helper.js" type="text/javascript"></script>
<script type="text/javascript">
template.helper('showLevel', function (level) {
	switch(level){
    	case 0:
    		return '<span class="level_error">错误</span>';
    	case 1:
    		return '<span class="level_warning">警告</span>';
    	case 2:
    		return '<span class="level_info">信息</span>';
    	case 3:
    		return '<span class="level_debug">调试</span>';
    	default:
    		return '';
	}
});
function get_page(){
    $.getJSON(
    	'<?php echo $list_url;?>',       
        {
              begin: (current_status.page_num - 1) * current_status.page_size,
              length: current_status.page_size
          },
          function(rs){
              if(rs.err===0){
                current_status.page_count = Math.ceil(rs.data.record_count/current_status.page_size);
                //呈现内容
                $('#rightinfo').html(template('list', $.extend({},current_status,rs.data)));
                //显示分页
                laypage({
                    cont: 'page_bar', //容器。值支持id名、原生dom对象，jquery对象。【如该容器为】：<div id="page1"></div>
                    pages: current_status.page_count, //通过后台拿到的总页数
                    curr: current_status.page_num, //当前页
                    jump: function(obj, is_self){ //触发分页后的回调
                        if(!is_self){ //点击跳页触发函数自身，并传递当前页：obj.curr
                            current_status.page_num = obj.curr;
                            get_page();
                        }
                    }
                });
              }else if(rs.err===4){
                  //数据实际页数减少，但前端没有刷新，仍旧请求不存在的页码，返回的是“列表为空”的错误
                  current_status.page_num --;
                  get_page();
              }else{
                  layer.msg(rs.msg, {icon:2,time:2000});
              }            
        }
    );
};
//加载第一页
var current_status = { page_num:1, page_size:20, page_count:1 };
get_page();
</script>